﻿using System;
using System.Text;
using System.Configuration;
using MediaPortal.Configuration;

namespace MPMovieCatalog.DAO
{
    class ConnectionUtil
    {
        private static string m_connectionString = null;

        public static string ConnectionString
        {
            get {
                if (m_connectionString == null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Data Source=");
                    sb.Append(GetDatabasePath());
                    sb.Append(";");

                    m_connectionString = sb.ToString();
                }
                return m_connectionString; 
            }
            set { m_connectionString = value; }
        }

        private static string GetDatabasePath()
        {
            string databasePath = ConfigurationSettings.AppSettings["databasePath"];
            if (databasePath == null || "".Equals(databasePath))
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(Config.GetFolder(Config.Dir.Database));
                sb.Append(@"VideoDatabaseV5.db3");

                databasePath = sb.ToString();
            }

            return databasePath;
        }

        public object doInConnection()
        {
            return null;
        }
    }
}
